{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QjHMHmrUW0Vg"
      },
      "source": [
        "# Training Prediction Models Directly Within PostgreSQL Using EvaDB\n",
        "In this tutorial, we'll harness EvaDB's model training capabilities to predict home rental prices, showcasing how EvaDB seamlessly integrates AI into your PostgreSQL database.\n",
        "<table align=\"left\">\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/georgia-tech-db/eva/blob/staging/tutorials/17-home-rental-prediction.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\"/> Run on Google Colab</a>\n",
        "  </td>\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://github.com/georgia-tech-db/eva/blob/staging/tutorials/17-home-rental-prediction.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\"/> View source on GitHub</a>\n",
        "  </td>\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://github.com/georgia-tech-db/eva/raw/staging/tutorials/17-home-rental-prediction.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /> Download notebook</a>\n",
        "  </td>\n",
        "</table><br><br>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GHToaA_NKiHY"
      },
      "source": [
        "## Setup"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f1GutjuqECBh"
      },
      "source": [
        "### Install and Launch the PostgreSQL Server\n",
        "\n",
        "To kick things off, we'll start by setting up the PostgreSQL database backend. If you already have a PostgreSQL server up and running, you can skip this step and proceed directly to [installing EvaDB](#install-evadb)."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Z7PodOEEEDsQ",
        "outputId": "83265c05-b542-431b-900d-bb39a9ad53c6"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The following additional packages will be installed:\n",
            "  libcommon-sense-perl libjson-perl libjson-xs-perl libtypes-serialiser-perl logrotate netbase\n",
            "  postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common ssl-cert sysstat\n",
            "Suggested packages:\n",
            "  bsd-mailx | mailx postgresql-doc postgresql-doc-14 isag\n",
            "The following NEW packages will be installed:\n",
            "  libcommon-sense-perl libjson-perl libjson-xs-perl libtypes-serialiser-perl logrotate netbase\n",
            "  postgresql postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common ssl-cert\n",
            "  sysstat\n",
            "0 upgraded, 13 newly installed, 0 to remove and 19 not upgraded.\n",
            "Need to get 18.3 MB of archives.\n",
            "After this operation, 51.5 MB of additional disk space will be used.\n",
            "Preconfiguring packages ...\n",
            "Selecting previously unselected package logrotate.\n",
            "(Reading database ... 120874 files and directories currently installed.)\n",
            "Preparing to unpack .../00-logrotate_3.19.0-1ubuntu1.1_amd64.deb ...\n",
            "Unpacking logrotate (3.19.0-1ubuntu1.1) ...\n",
            "Selecting previously unselected package netbase.\n",
            "Preparing to unpack .../01-netbase_6.3_all.deb ...\n",
            "Unpacking netbase (6.3) ...\n",
            "Selecting previously unselected package libcommon-sense-perl:amd64.\n",
            "Preparing to unpack .../02-libcommon-sense-perl_3.75-2build1_amd64.deb ...\n",
            "Unpacking libcommon-sense-perl:amd64 (3.75-2build1) ...\n",
            "Selecting previously unselected package libjson-perl.\n",
            "Preparing to unpack .../03-libjson-perl_4.04000-1_all.deb ...\n",
            "Unpacking libjson-perl (4.04000-1) ...\n",
            "Selecting previously unselected package libtypes-serialiser-perl.\n",
            "Preparing to unpack .../04-libtypes-serialiser-perl_1.01-1_all.deb ...\n",
            "Unpacking libtypes-serialiser-perl (1.01-1) ...\n",
            "Selecting previously unselected package libjson-xs-perl.\n",
            "Preparing to unpack .../05-libjson-xs-perl_4.030-1build3_amd64.deb ...\n",
            "Unpacking libjson-xs-perl (4.030-1build3) ...\n",
            "Selecting previously unselected package postgresql-client-common.\n",
            "Preparing to unpack .../06-postgresql-client-common_238_all.deb ...\n",
            "Unpacking postgresql-client-common (238) ...\n",
            "Selecting previously unselected package postgresql-client-14.\n",
            "Preparing to unpack .../07-postgresql-client-14_14.9-0ubuntu0.22.04.1_amd64.deb ...\n",
            "Unpacking postgresql-client-14 (14.9-0ubuntu0.22.04.1) ...\n",
            "Selecting previously unselected package ssl-cert.\n",
            "Preparing to unpack .../08-ssl-cert_1.1.2_all.deb ...\n",
            "Unpacking ssl-cert (1.1.2) ...\n",
            "Selecting previously unselected package postgresql-common.\n",
            "Preparing to unpack .../09-postgresql-common_238_all.deb ...\n",
            "Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'\n",
            "Unpacking postgresql-common (238) ...\n",
            "Selecting previously unselected package postgresql-14.\n",
            "Preparing to unpack .../10-postgresql-14_14.9-0ubuntu0.22.04.1_amd64.deb ...\n",
            "Unpacking postgresql-14 (14.9-0ubuntu0.22.04.1) ...\n",
            "Selecting previously unselected package postgresql.\n",
            "Preparing to unpack .../11-postgresql_14+238_all.deb ...\n",
            "Unpacking postgresql (14+238) ...\n",
            "Selecting previously unselected package sysstat.\n",
            "Preparing to unpack .../12-sysstat_12.5.2-2ubuntu0.2_amd64.deb ...\n",
            "Unpacking sysstat (12.5.2-2ubuntu0.2) ...\n",
            "Setting up logrotate (3.19.0-1ubuntu1.1) ...\n",
            "Created symlink /etc/systemd/system/timers.target.wants/logrotate.timer → /lib/systemd/system/logrotate.timer.\n",
            "Setting up libcommon-sense-perl:amd64 (3.75-2build1) ...\n",
            "Setting up ssl-cert (1.1.2) ...\n",
            "Setting up libtypes-serialiser-perl (1.01-1) ...\n",
            "Setting up libjson-perl (4.04000-1) ...\n",
            "Setting up netbase (6.3) ...\n",
            "Setting up sysstat (12.5.2-2ubuntu0.2) ...\n",
            "\n",
            "Creating config file /etc/default/sysstat with new version\n",
            "update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode\n",
            "Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer → /lib/systemd/system/sysstat-collect.timer.\n",
            "Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer → /lib/systemd/system/sysstat-summary.timer.\n",
            "Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.\n",
            "Setting up postgresql-client-common (238) ...\n",
            "Setting up libjson-xs-perl (4.030-1build3) ...\n",
            "Setting up postgresql-client-14 (14.9-0ubuntu0.22.04.1) ...\n",
            "update-alternatives: using /usr/share/postgresql/14/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode\n",
            "Setting up postgresql-common (238) ...\n",
            "Adding user postgres to group ssl-cert\n",
            "\n",
            "Creating config file /etc/postgresql-common/createcluster.conf with new version\n",
            "Building PostgreSQL dictionaries from installed myspell/hunspell packages...\n",
            "Removing obsolete dictionary files:\n",
            "Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.\n",
            "Setting up postgresql-14 (14.9-0ubuntu0.22.04.1) ...\n",
            "Creating new PostgreSQL cluster 14/main ...\n",
            "/usr/lib/postgresql/14/bin/initdb -D /var/lib/postgresql/14/main --auth-local peer --auth-host scram-sha-256 --no-instructions\n",
            "The files belonging to this database system will be owned by user \"postgres\".\n",
            "This user must also own the server process.\n",
            "\n",
            "The database cluster will be initialized with locale \"en_US.UTF-8\".\n",
            "The default database encoding has accordingly been set to \"UTF8\".\n",
            "The default text search configuration will be set to \"english\".\n",
            "\n",
            "Data page checksums are disabled.\n",
            "\n",
            "fixing permissions on existing directory /var/lib/postgresql/14/main ... ok\n",
            "creating subdirectories ... ok\n",
            "selecting dynamic shared memory implementation ... posix\n",
            "selecting default max_connections ... 100\n",
            "selecting default shared_buffers ... 128MB\n",
            "selecting default time zone ... Etc/UTC\n",
            "creating configuration files ... ok\n",
            "running bootstrap script ... ok\n",
            "performing post-bootstrap initialization ... ok\n",
            "syncing data to disk ... ok\n",
            "update-alternatives: using /usr/share/postgresql/14/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode\n",
            "invoke-rc.d: could not determine current runlevel\n",
            "invoke-rc.d: policy-rc.d denied execution of start.\n",
            "Setting up postgresql (14+238) ...\n",
            "Processing triggers for man-db (2.10.2-1) ...\n",
            " * Starting PostgreSQL 14 database server\n",
            "   ...done.\n"
          ]
        }
      ],
      "source": [
        "!apt -qq install postgresql\n",
        "!service postgresql start"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hfBwvBTfEWIR"
      },
      "source": [
        "### Create User and Database"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UrlfWZOkEa4V",
        "outputId": "477a18d7-93cf-432b-bbea-0115f9f48454"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "CREATE ROLE\n",
            "CREATE DATABASE\n"
          ]
        }
      ],
      "source": [
        "!sudo -u postgres psql -c \"CREATE USER eva WITH SUPERUSER PASSWORD 'password'\"\n",
        "!sudo -u postgres psql -c \"CREATE DATABASE evadb\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "H2m43vfZE8x6"
      },
      "source": [
        "### Prettify  Output"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "EZf65ZkcFIX7"
      },
      "outputs": [],
      "source": [
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "from IPython.core.display import display, HTML\n",
        "def pretty_print(df):\n",
        "    return display(HTML( df.to_html().replace(\"\\\\n\",\"<br>\")))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CpYS09iMEhaT"
      },
      "source": [
        "### Installing EvaDB\n",
        "<a id='install_evadb'></a>\n",
        "We install EvaDB along with the necessary PostgreSQL and Ludwig dependencies."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "NoAykveeElqm"
      },
      "outputs": [],
      "source": [
        "%pip install --quiet \"evadb[postgres,xgboost,ludwig]\"\n",
        "\n",
        "import evadb\n",
        "cursor = evadb.connect().cursor()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mUN-rlV8LHxN"
      },
      "source": [
        "## Load data into PostgresSQL\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nKwAY9eMFoc8"
      },
      "source": [
        "### Setting up a Data Source in EvaDB\n",
        "To establish a direct connection between EvaDB and underlying database systems such as PostgreSQL, we will create a data source. This process entails supplying EvaDB with the connection credentials for the active PostgreSQL server."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 80
        },
        "id": "IsP6rLZ2Ftxo",
        "outputId": "84a41fb6-5f1f-4d7c-e219-f08a2e73b088"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                                   0\n",
              "0  The database postgres_data has been successful..."
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-91ffca60-bfcf-4e4b-ad03-1c7ff0f85bc6\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>The database postgres_data has been successful...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-91ffca60-bfcf-4e4b-ad03-1c7ff0f85bc6')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-91ffca60-bfcf-4e4b-ad03-1c7ff0f85bc6 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-91ffca60-bfcf-4e4b-ad03-1c7ff0f85bc6');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 11
        }
      ],
      "source": [
        "params = {\n",
        "    \"user\": \"eva\",\n",
        "    \"password\": \"password\",\n",
        "    \"host\": \"localhost\",\n",
        "    \"port\": \"5432\",\n",
        "    \"database\": \"evadb\",\n",
        "}\n",
        "query = f\"CREATE DATABASE postgres_data WITH ENGINE = 'postgres', PARAMETERS = {params};\"\n",
        "cursor.query(query).df()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Lwls48NQJb6G"
      },
      "source": [
        "### Loading Home Property Sales Data from CSV into PostgreSQL\n",
        "\n",
        "In this step, we will import the [House Property Sales](https://www.kaggle.com/datasets/htagholdings/property-sales?resource=download) dataset into our PostgreSQL database. If you already have the data stored in PostgreSQL and are ready to proceed with the prediction model training, feel free to skip this section and head directly to the [model training process](#train-the-prediction-model).\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "msbHcP_xJpFV",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "0eca67d7-e820-42ed-941e-9ca38ceade76"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "--2023-10-26 18:33:10--  https://www.dropbox.com/scl/fi/gy2682i66a8l2tqsowm5x/home_rentals.csv?rlkey=e080k02rv5205h4ullfjdr8lw\n",
            "Resolving www.dropbox.com (www.dropbox.com)... 162.125.3.18, 2620:100:6018:18::a27d:312\n",
            "Connecting to www.dropbox.com (www.dropbox.com)|162.125.3.18|:443... connected.\n",
            "HTTP request sent, awaiting response... 302 Found\n",
            "Location: https://uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com/cd/0/inline/CGVkpQp8MQys_mL2iZ4WZL0mLTIryv1kHm9c6YlkGomsP279V5incJvOz05jfx5oqY0zKLKoMNcksLTrXBuk3MgOYSnfeHIjuKAzyWM5fZKfHS1qfV9_8EQsi--9jZx53LFu_MvgxiKWMys7t4DrWF_1/file# [following]\n",
            "--2023-10-26 18:33:11--  https://uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com/cd/0/inline/CGVkpQp8MQys_mL2iZ4WZL0mLTIryv1kHm9c6YlkGomsP279V5incJvOz05jfx5oqY0zKLKoMNcksLTrXBuk3MgOYSnfeHIjuKAzyWM5fZKfHS1qfV9_8EQsi--9jZx53LFu_MvgxiKWMys7t4DrWF_1/file\n",
            "Resolving uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com (uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com)... 162.125.3.15, 2620:100:601b:15::a27d:80f\n",
            "Connecting to uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com (uc8d990fb5d1437b8351f26de88a.dl.dropboxusercontent.com)|162.125.3.15|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 204532 (200K) [text/plain]\n",
            "Saving to: ‘/content/home_rentals.csv’\n",
            "\n",
            "/content/home_renta 100%[===================>] 199.74K  --.-KB/s    in 0.04s   \n",
            "\n",
            "2023-10-26 18:33:11 (4.91 MB/s) - ‘/content/home_rentals.csv’ saved [204532/204532]\n",
            "\n"
          ]
        }
      ],
      "source": [
        "!mkdir -p content\n",
        "!wget -nc -O /content/home_rentals.csv https://www.dropbox.com/scl/fi/gy2682i66a8l2tqsowm5x/home_rentals.csv?rlkey=e080k02rv5205h4ullfjdr8lw&raw=1"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 80
        },
        "id": "MhYfovbzNB-k",
        "outputId": "3b453405-f0dd-47d9-b867-3d552cdeebff"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "    status\n",
              "0  success"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-856ca5aa-70e5-4093-bef1-aad5bf9fea1a\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>status</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>success</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-856ca5aa-70e5-4093-bef1-aad5bf9fea1a')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-856ca5aa-70e5-4093-bef1-aad5bf9fea1a button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-856ca5aa-70e5-4093-bef1-aad5bf9fea1a');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 13
        }
      ],
      "source": [
        "cursor.query(\"\"\"\n",
        "  USE postgres_data {\n",
        "    CREATE TABLE IF NOT EXISTS home_rentals (\n",
        "      number_of_rooms INT,\n",
        "      number_of_bathrooms INT,\n",
        "      sqft INT,\n",
        "      location VARCHAR(128),\n",
        "      days_on_market INT,\n",
        "      initial_price INT,\n",
        "      neighborhood VARCHAR(128),\n",
        "      rental_price FLOAT\n",
        "    )\n",
        "  }\n",
        "\"\"\").df()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 80
        },
        "id": "OH8Fxn0SNYO3",
        "outputId": "06825af6-9feb-4949-ee7a-73891f4487c4"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "    status\n",
              "0  success"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-5a3961cf-cc34-4e8f-83a3-41ceaca92b1b\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>status</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>success</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5a3961cf-cc34-4e8f-83a3-41ceaca92b1b')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-5a3961cf-cc34-4e8f-83a3-41ceaca92b1b button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-5a3961cf-cc34-4e8f-83a3-41ceaca92b1b');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 14
        }
      ],
      "source": [
        "cursor.query(\"\"\"\n",
        "  USE postgres_data {\n",
        "    COPY home_rentals(number_of_rooms, number_of_bathrooms, sqft, location, days_on_market, initial_price, neighborhood, rental_price)\n",
        "    FROM '/content/home_rentals.csv'\n",
        "    DELIMITER ',' CSV HEADER\n",
        "  }\n",
        "\"\"\").df()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vKXHBLtxNsbg"
      },
      "source": [
        "### Preview the Data\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HSj_2sif8uEX"
      },
      "source": [
        "Within the home_rentals table, there are 8 columns at our disposal. Our objective is to utilize the remaining 7 columns to make predictions for the rental_price."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        },
        "id": "20_IEby7N1Pe",
        "outputId": "9fd8bcfb-2be7-4f59-e4c2-812c91a6a325"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   rental_price  number_of_bathrooms  sqft  initial_price  number_of_rooms  \\\n",
              "0        2167.0                    1   674           2167                1   \n",
              "1        1883.0                    1   554           1883                1   \n",
              "2        2431.0                    1   529           2431                0   \n",
              "\n",
              "   days_on_market location neighborhood  \n",
              "0               1     good     downtown  \n",
              "1              19     poor     westbrae  \n",
              "2               3    great   south_side  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-e2385a39-e37b-4af2-8541-796a2d8eb033\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>rental_price</th>\n",
              "      <th>number_of_bathrooms</th>\n",
              "      <th>sqft</th>\n",
              "      <th>initial_price</th>\n",
              "      <th>number_of_rooms</th>\n",
              "      <th>days_on_market</th>\n",
              "      <th>location</th>\n",
              "      <th>neighborhood</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2167.0</td>\n",
              "      <td>1</td>\n",
              "      <td>674</td>\n",
              "      <td>2167</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>good</td>\n",
              "      <td>downtown</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1883.0</td>\n",
              "      <td>1</td>\n",
              "      <td>554</td>\n",
              "      <td>1883</td>\n",
              "      <td>1</td>\n",
              "      <td>19</td>\n",
              "      <td>poor</td>\n",
              "      <td>westbrae</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2431.0</td>\n",
              "      <td>1</td>\n",
              "      <td>529</td>\n",
              "      <td>2431</td>\n",
              "      <td>0</td>\n",
              "      <td>3</td>\n",
              "      <td>great</td>\n",
              "      <td>south_side</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e2385a39-e37b-4af2-8541-796a2d8eb033')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-e2385a39-e37b-4af2-8541-796a2d8eb033 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-e2385a39-e37b-4af2-8541-796a2d8eb033');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-07ed7fd5-a749-4f4b-98c4-d96ad24c0ff1\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-07ed7fd5-a749-4f4b-98c4-d96ad24c0ff1')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-07ed7fd5-a749-4f4b-98c4-d96ad24c0ff1 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ],
      "source": [
        "cursor.query(\"SELECT * FROM postgres_data.home_rentals LIMIT 3;\").df()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7DX411TFO-Lp"
      },
      "source": [
        "## Training Model\n",
        "\n",
        "Next, we employ EvaDB to facilitate the training of an ML model, which will enable us to predict `home rental prices`."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hoLzadFlPOvh"
      },
      "source": [
        "### Train the prediction Model using Ludwig\n",
        "For this purpose, we harness the capabilities of the [ludwig](https://ludwig.ai/latest/) engine to train our prediction model. We employ the `automl` feature to automatically determine the optimal hyperparameters. Keep in mind that `TIME_LIMIT` specifies the time budget allocated for the training process."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IFstPBI8UINv"
      },
      "outputs": [],
      "source": [
        "cursor.query(\"\"\"\n",
        "  CREATE OR REPLACE FUNCTION PredictHouseRent FROM\n",
        "  ( SELECT * FROM postgres_data.home_rentals )\n",
        "  TYPE Ludwig\n",
        "  PREDICT 'rental_price'\n",
        "  TIME_LIMIT 3600;\n",
        "\"\"\").df()"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Train the prediction Model using XGBoost\n",
        "With XGBoost integration, we harness the capabilities of the [XGBoost](https://xgboost.readthedocs.io/en/stable/) engine to train our prediction model. We employ the `Flaml` AutoML model to automatically determine the optimal hyperparameters. We can utilize `TIME_LIMIT` to specify the time budget allocated for the training process. Similarly you can use the `METRIC` parameter to determine the accuracy/error metric for training the model. `TASK` parameter can be used to specify whether you want to perform a `classification` task or `regression` task."
      ],
      "metadata": {
        "id": "1MRKIT0OQ7R8"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "cursor.query(\"\"\"\n",
        "  CREATE OR REPLACE FUNCTION PredictHouseRent FROM\n",
        "  ( SELECT * FROM postgres_data.home_rentals )\n",
        "  TYPE XGBoost\n",
        "  PREDICT 'rental_price'\n",
        "  TIME_LIMIT 180\n",
        "  METRIC 'rmse'\n",
        "  TASK 'regression';\n",
        "\"\"\").df()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "7Zl8nJfaSglz",
        "outputId": "ad6fd61c-4fd5-4b6d-a982-79408803a765"
      },
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[flaml.automl.logger: 10-26 18:42:28] {1679} INFO - task = regression\n",
            "[flaml.automl.logger: 10-26 18:42:28] {1690} INFO - Evaluation method: cv\n",
            "[flaml.automl.logger: 10-26 18:42:28] {1788} INFO - Minimizing error metric: rmse\n",
            "[flaml.automl.logger: 10-26 18:42:28] {1900} INFO - List of ML learners in AutoML Run: ['xgboost']\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 0, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2344} INFO - Estimated sufficient time budget=1240s. Estimated necessary time budget=1s.\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.2s,\testimator xgboost's best error=873.7432,\tbest estimator xgboost's best error=873.7432\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 1, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.3s,\testimator xgboost's best error=873.7432,\tbest estimator xgboost's best error=873.7432\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 2, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.3s,\testimator xgboost's best error=441.7846,\tbest estimator xgboost's best error=441.7846\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 3, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.4s,\testimator xgboost's best error=170.0591,\tbest estimator xgboost's best error=170.0591\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 4, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.5s,\testimator xgboost's best error=170.0591,\tbest estimator xgboost's best error=170.0591\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 5, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.6s,\testimator xgboost's best error=170.0591,\tbest estimator xgboost's best error=170.0591\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 6, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2391} INFO -  at 0.7s,\testimator xgboost's best error=95.8596,\tbest estimator xgboost's best error=95.8596\n",
            "[flaml.automl.logger: 10-26 18:42:28] {2218} INFO - iteration 7, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 0.8s,\testimator xgboost's best error=95.8596,\tbest estimator xgboost's best error=95.8596\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 8, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 0.9s,\testimator xgboost's best error=95.8596,\tbest estimator xgboost's best error=95.8596\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 9, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.0s,\testimator xgboost's best error=53.9540,\tbest estimator xgboost's best error=53.9540\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 10, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.1s,\testimator xgboost's best error=53.9540,\tbest estimator xgboost's best error=53.9540\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 11, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.1s,\testimator xgboost's best error=53.9540,\tbest estimator xgboost's best error=53.9540\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 12, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.3s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 13, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.4s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 14, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.5s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 15, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2391} INFO -  at 1.6s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:29] {2218} INFO - iteration 16, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2391} INFO -  at 1.8s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2218} INFO - iteration 17, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2391} INFO -  at 1.8s,\testimator xgboost's best error=31.0753,\tbest estimator xgboost's best error=31.0753\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2218} INFO - iteration 18, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2391} INFO -  at 2.0s,\testimator xgboost's best error=20.7490,\tbest estimator xgboost's best error=20.7490\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2218} INFO - iteration 19, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2391} INFO -  at 2.1s,\testimator xgboost's best error=20.7490,\tbest estimator xgboost's best error=20.7490\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2218} INFO - iteration 20, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2391} INFO -  at 2.5s,\testimator xgboost's best error=19.0545,\tbest estimator xgboost's best error=19.0545\n",
            "[flaml.automl.logger: 10-26 18:42:30] {2218} INFO - iteration 21, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2391} INFO -  at 2.9s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2218} INFO - iteration 22, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2391} INFO -  at 3.3s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2218} INFO - iteration 23, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2391} INFO -  at 3.6s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:31] {2218} INFO - iteration 24, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:32] {2391} INFO -  at 4.0s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:32] {2218} INFO - iteration 25, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:32] {2391} INFO -  at 4.2s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:32] {2218} INFO - iteration 26, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2391} INFO -  at 4.9s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2218} INFO - iteration 27, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2391} INFO -  at 5.1s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2218} INFO - iteration 28, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2391} INFO -  at 5.5s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2218} INFO - iteration 29, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2391} INFO -  at 5.6s,\testimator xgboost's best error=17.9867,\tbest estimator xgboost's best error=17.9867\n",
            "[flaml.automl.logger: 10-26 18:42:33] {2218} INFO - iteration 30, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:35] {2391} INFO -  at 7.0s,\testimator xgboost's best error=12.8256,\tbest estimator xgboost's best error=12.8256\n",
            "[flaml.automl.logger: 10-26 18:42:35] {2218} INFO - iteration 31, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:36] {2391} INFO -  at 8.2s,\testimator xgboost's best error=12.8256,\tbest estimator xgboost's best error=12.8256\n",
            "[flaml.automl.logger: 10-26 18:42:36] {2218} INFO - iteration 32, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:37] {2391} INFO -  at 9.2s,\testimator xgboost's best error=12.8256,\tbest estimator xgboost's best error=12.8256\n",
            "[flaml.automl.logger: 10-26 18:42:37] {2218} INFO - iteration 33, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:39] {2391} INFO -  at 10.8s,\testimator xgboost's best error=12.8256,\tbest estimator xgboost's best error=12.8256\n",
            "[flaml.automl.logger: 10-26 18:42:39] {2218} INFO - iteration 34, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:40] {2391} INFO -  at 12.1s,\testimator xgboost's best error=11.7529,\tbest estimator xgboost's best error=11.7529\n",
            "[flaml.automl.logger: 10-26 18:42:40] {2218} INFO - iteration 35, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:43] {2391} INFO -  at 15.5s,\testimator xgboost's best error=11.7529,\tbest estimator xgboost's best error=11.7529\n",
            "[flaml.automl.logger: 10-26 18:42:43] {2218} INFO - iteration 36, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:44] {2391} INFO -  at 15.8s,\testimator xgboost's best error=11.7529,\tbest estimator xgboost's best error=11.7529\n",
            "[flaml.automl.logger: 10-26 18:42:44] {2218} INFO - iteration 37, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:45] {2391} INFO -  at 16.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:45] {2218} INFO - iteration 38, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:45] {2391} INFO -  at 17.7s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:45] {2218} INFO - iteration 39, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:47] {2391} INFO -  at 19.0s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:47] {2218} INFO - iteration 40, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:48] {2391} INFO -  at 20.0s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:48] {2218} INFO - iteration 41, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:48] {2391} INFO -  at 20.4s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:48] {2218} INFO - iteration 42, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:52] {2391} INFO -  at 24.2s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:52] {2218} INFO - iteration 43, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:54] {2391} INFO -  at 26.0s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:54] {2218} INFO - iteration 44, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:55] {2391} INFO -  at 27.4s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:55] {2218} INFO - iteration 45, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:58] {2391} INFO -  at 30.0s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:58] {2218} INFO - iteration 46, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:42:59] {2391} INFO -  at 30.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:42:59] {2218} INFO - iteration 47, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:01] {2391} INFO -  at 33.4s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:01] {2218} INFO - iteration 48, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:03] {2391} INFO -  at 34.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:03] {2218} INFO - iteration 49, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:04] {2391} INFO -  at 36.5s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:04] {2218} INFO - iteration 50, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:05] {2391} INFO -  at 37.7s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:05] {2218} INFO - iteration 51, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:08] {2391} INFO -  at 40.1s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:08] {2218} INFO - iteration 52, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:08] {2391} INFO -  at 40.6s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:08] {2218} INFO - iteration 53, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:09] {2391} INFO -  at 41.7s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:09] {2218} INFO - iteration 54, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:11] {2391} INFO -  at 42.8s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:11] {2218} INFO - iteration 55, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:12] {2391} INFO -  at 43.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:12] {2218} INFO - iteration 56, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:13] {2391} INFO -  at 44.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:13] {2218} INFO - iteration 57, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:18] {2391} INFO -  at 50.3s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:18] {2218} INFO - iteration 58, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:19] {2391} INFO -  at 50.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:19] {2218} INFO - iteration 59, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:20] {2391} INFO -  at 51.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:20] {2218} INFO - iteration 60, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:22] {2391} INFO -  at 54.5s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:22] {2218} INFO - iteration 61, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:24] {2391} INFO -  at 56.0s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:24] {2218} INFO - iteration 62, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:25] {2391} INFO -  at 56.9s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:25] {2218} INFO - iteration 63, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:26] {2391} INFO -  at 58.2s,\testimator xgboost's best error=9.6447,\tbest estimator xgboost's best error=9.6447\n",
            "[flaml.automl.logger: 10-26 18:43:26] {2218} INFO - iteration 64, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:27] {2391} INFO -  at 59.1s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:27] {2218} INFO - iteration 65, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:27] {2391} INFO -  at 59.4s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:27] {2218} INFO - iteration 66, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:33] {2391} INFO -  at 65.2s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:33] {2218} INFO - iteration 67, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:36] {2391} INFO -  at 68.0s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:36] {2218} INFO - iteration 68, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:37] {2391} INFO -  at 68.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:37] {2218} INFO - iteration 69, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:39] {2391} INFO -  at 71.6s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:39] {2218} INFO - iteration 70, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:40] {2391} INFO -  at 72.0s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:40] {2218} INFO - iteration 71, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:41] {2391} INFO -  at 73.2s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:41] {2218} INFO - iteration 72, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:42] {2391} INFO -  at 73.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:42] {2218} INFO - iteration 73, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:43] {2391} INFO -  at 75.2s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:43] {2218} INFO - iteration 74, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:44] {2391} INFO -  at 75.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:44] {2218} INFO - iteration 75, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:44] {2391} INFO -  at 76.5s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:44] {2218} INFO - iteration 76, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:46] {2391} INFO -  at 77.9s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:46] {2218} INFO - iteration 77, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:47] {2391} INFO -  at 78.9s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:47] {2218} INFO - iteration 78, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:47] {2391} INFO -  at 79.7s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:47] {2218} INFO - iteration 79, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:49] {2391} INFO -  at 81.5s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:49] {2218} INFO - iteration 80, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:50] {2391} INFO -  at 82.5s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:50] {2218} INFO - iteration 81, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:51] {2391} INFO -  at 83.7s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:51] {2218} INFO - iteration 82, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:53] {2391} INFO -  at 85.5s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:53] {2218} INFO - iteration 83, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:55] {2391} INFO -  at 86.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:55] {2218} INFO - iteration 84, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:55] {2391} INFO -  at 87.7s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:55] {2218} INFO - iteration 85, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:56] {2391} INFO -  at 88.1s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:56] {2218} INFO - iteration 86, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:43:59] {2391} INFO -  at 90.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:43:59] {2218} INFO - iteration 87, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:00] {2391} INFO -  at 92.3s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:00] {2218} INFO - iteration 88, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:01] {2391} INFO -  at 92.9s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:01] {2218} INFO - iteration 89, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:02] {2391} INFO -  at 94.2s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:02] {2218} INFO - iteration 90, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:02] {2391} INFO -  at 94.7s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:02] {2218} INFO - iteration 91, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:04] {2391} INFO -  at 96.0s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:04] {2218} INFO - iteration 92, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:04] {2391} INFO -  at 96.7s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:04] {2218} INFO - iteration 93, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:06] {2391} INFO -  at 97.8s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:06] {2218} INFO - iteration 94, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:07] {2391} INFO -  at 99.4s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:07] {2218} INFO - iteration 95, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:09] {2391} INFO -  at 101.5s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:09] {2218} INFO - iteration 96, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:10] {2391} INFO -  at 102.6s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:10] {2218} INFO - iteration 97, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:11] {2391} INFO -  at 103.4s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:11] {2218} INFO - iteration 98, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:13] {2391} INFO -  at 105.1s,\testimator xgboost's best error=9.0431,\tbest estimator xgboost's best error=9.0431\n",
            "[flaml.automl.logger: 10-26 18:44:13] {2218} INFO - iteration 99, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:14] {2391} INFO -  at 106.5s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:14] {2218} INFO - iteration 100, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:15] {2391} INFO -  at 107.4s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:15] {2218} INFO - iteration 101, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:20] {2391} INFO -  at 111.9s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:20] {2218} INFO - iteration 102, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:20] {2391} INFO -  at 112.4s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:20] {2218} INFO - iteration 103, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:21] {2391} INFO -  at 113.4s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:21] {2218} INFO - iteration 104, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:24] {2391} INFO -  at 116.1s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:24] {2218} INFO - iteration 105, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:25] {2391} INFO -  at 117.5s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:25] {2218} INFO - iteration 106, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:29] {2391} INFO -  at 121.5s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:29] {2218} INFO - iteration 107, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:31] {2391} INFO -  at 122.9s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:31] {2218} INFO - iteration 108, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:35] {2391} INFO -  at 127.2s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:35] {2218} INFO - iteration 109, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:37] {2391} INFO -  at 128.9s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:37] {2218} INFO - iteration 110, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:38] {2391} INFO -  at 130.2s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:38] {2218} INFO - iteration 111, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:38] {2391} INFO -  at 130.6s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:38] {2218} INFO - iteration 112, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:44] {2391} INFO -  at 136.0s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:44] {2218} INFO - iteration 113, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:49] {2391} INFO -  at 141.6s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:49] {2218} INFO - iteration 114, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:50] {2391} INFO -  at 142.1s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:50] {2218} INFO - iteration 115, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:50] {2391} INFO -  at 142.6s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:50] {2218} INFO - iteration 116, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:56] {2391} INFO -  at 148.1s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:56] {2218} INFO - iteration 117, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:57] {2391} INFO -  at 149.6s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:57] {2218} INFO - iteration 118, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:44:59] {2391} INFO -  at 150.8s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:44:59] {2218} INFO - iteration 119, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:00] {2391} INFO -  at 151.9s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:00] {2218} INFO - iteration 120, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:04] {2391} INFO -  at 156.3s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:04] {2218} INFO - iteration 121, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:06] {2391} INFO -  at 157.8s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:06] {2218} INFO - iteration 122, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:07] {2391} INFO -  at 159.7s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:07] {2218} INFO - iteration 123, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:09] {2391} INFO -  at 161.7s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:09] {2218} INFO - iteration 124, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:10] {2391} INFO -  at 162.7s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:10] {2218} INFO - iteration 125, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:11] {2391} INFO -  at 163.2s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:11] {2218} INFO - iteration 126, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:15] {2391} INFO -  at 167.2s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:15] {2218} INFO - iteration 127, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:15] {2391} INFO -  at 167.7s,\testimator xgboost's best error=8.9214,\tbest estimator xgboost's best error=8.9214\n",
            "[flaml.automl.logger: 10-26 18:45:15] {2218} INFO - iteration 128, current learner xgboost\n",
            "[flaml.automl.logger: 10-26 18:45:22] {2391} INFO -  at 174.1s,\testimator xgboost's best error=8.4442,\tbest estimator xgboost's best error=8.4442\n",
            "[flaml.automl.logger: 10-26 18:45:23] {2627} INFO - retrain xgboost for 0.9s\n",
            "[flaml.automl.logger: 10-26 18:45:23] {2630} INFO - retrained model: XGBRegressor(base_score=None, booster=None, callbacks=[],\n",
            "             colsample_bylevel=0.9937172947585778, colsample_bynode=None,\n",
            "             colsample_bytree=1.0, device=None, early_stopping_rounds=None,\n",
            "             enable_categorical=False, eval_metric=None, feature_types=None,\n",
            "             gamma=None, grow_policy='lossguide', importance_type=None,\n",
            "             interaction_constraints=None, learning_rate=0.023369112362873073,\n",
            "             max_bin=None, max_cat_threshold=None, max_cat_to_onehot=None,\n",
            "             max_delta_step=None, max_depth=0, max_leaves=131,\n",
            "             min_child_weight=2.39151823628023, missing=nan,\n",
            "             monotone_constraints=None, multi_strategy=None, n_estimators=363,\n",
            "             n_jobs=-1, num_parallel_tree=None, random_state=None, ...)\n",
            "[flaml.automl.logger: 10-26 18:45:23] {1930} INFO - fit succeeded\n",
            "[flaml.automl.logger: 10-26 18:45:23] {1931} INFO - Time taken to find the best model: 174.1169867515564\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                                  0\n",
              "0  Function PredictHouseRent added to the database."
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-49c2c92a-ecfe-49e0-a75d-b4736cd734b2\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Function PredictHouseRent added to the database.</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-49c2c92a-ecfe-49e0-a75d-b4736cd734b2')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-49c2c92a-ecfe-49e0-a75d-b4736cd734b2 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-49c2c92a-ecfe-49e0-a75d-b4736cd734b2');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AhItlDfBUHOo"
      },
      "source": [
        "### Utilizing the Prediction Model\n",
        "Following the model training, we proceed to employ the `PredictHouseRent`` model to make predictions for home rental prices."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        },
        "id": "_7m-QQG5U3_C",
        "outputId": "f8e77484-c2ce-4100-8edf-e8237799fc67"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   rental_price\n",
              "0   2166.502930\n",
              "1   1881.248047\n",
              "2   2429.649170\n",
              "3   5504.289062\n",
              "4   2272.817139\n",
              "5   4125.753906\n",
              "6   2222.618164\n",
              "7   2100.471191\n",
              "8   3870.793945\n",
              "9   2043.048096"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-f82ac135-a21f-43f4-bcf9-b9f02ec6870c\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>rental_price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2166.502930</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1881.248047</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2429.649170</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>5504.289062</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2272.817139</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>4125.753906</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>2222.618164</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>2100.471191</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>3870.793945</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>2043.048096</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-f82ac135-a21f-43f4-bcf9-b9f02ec6870c')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-f82ac135-a21f-43f4-bcf9-b9f02ec6870c button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-f82ac135-a21f-43f4-bcf9-b9f02ec6870c');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-dcbfc23d-c817-49db-9222-3db946a2c42c\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-dcbfc23d-c817-49db-9222-3db946a2c42c')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-dcbfc23d-c817-49db-9222-3db946a2c42c button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 20
        }
      ],
      "source": [
        "cursor.query(\"SELECT PredictHouseRent(*) FROM postgres_data.home_rentals LIMIT 10;\").df()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bRuPU8hVc3nv"
      },
      "source": [
        "We have the option to utilize a `LATERAL JOIN` to compare the actual rental prices in the `home_rentals` dataset with the predicted rental prices generated by the trained model, `PredictHouseRent`."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        },
        "id": "1rDikEWodBdX",
        "outputId": "be1eccf7-1c0a-439a-b7b0-1f25a1949b4b"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   rental_price  predicted_rental_price\n",
              "0      2167.000             2167.564697\n",
              "1      1883.000             1881.478516\n",
              "2      2431.000             2430.222656\n",
              "3      5510.000             5506.156738\n",
              "4      2272.000             2274.904297\n",
              "5      4123.812             4123.654785\n",
              "6      2224.000             2224.599609\n",
              "7      2104.000             2101.194824\n",
              "8      3861.000             3866.042725\n",
              "9      2041.000             2043.027222"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-1b6ccf35-5cc5-41e4-9351-d031bd07bca8\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>rental_price</th>\n",
              "      <th>predicted_rental_price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2167.000</td>\n",
              "      <td>2167.564697</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1883.000</td>\n",
              "      <td>1881.478516</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2431.000</td>\n",
              "      <td>2430.222656</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>5510.000</td>\n",
              "      <td>5506.156738</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2272.000</td>\n",
              "      <td>2274.904297</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>4123.812</td>\n",
              "      <td>4123.654785</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>2224.000</td>\n",
              "      <td>2224.599609</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>2104.000</td>\n",
              "      <td>2101.194824</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>3861.000</td>\n",
              "      <td>3866.042725</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>2041.000</td>\n",
              "      <td>2043.027222</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1b6ccf35-5cc5-41e4-9351-d031bd07bca8')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-1b6ccf35-5cc5-41e4-9351-d031bd07bca8 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-1b6ccf35-5cc5-41e4-9351-d031bd07bca8');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-15c9f7ba-1df9-48a2-aae4-dfe52f9f6376\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-15c9f7ba-1df9-48a2-aae4-dfe52f9f6376')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-15c9f7ba-1df9-48a2-aae4-dfe52f9f6376 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 21
        }
      ],
      "source": [
        "cursor.query(\"\"\"\n",
        "  SELECT rental_price, predicted_rental_price FROM postgres_data.home_rentals\n",
        "  JOIN LATERAL PredictHouseRent(*) AS Predicted(predicted_rental_price) LIMIT 10;\n",
        "\"\"\").df()"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [
        "GHToaA_NKiHY",
        "H2m43vfZE8x6"
      ],
      "provenance": [],
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
